<template>
  <div class="artical">
    <van-nav-bar title left-arrow @click-left="onClickLeft" fixed />
    <div class="detail">
      <div class="title">{{articalDetail.title}}</div>
      <div class="subtitle">
        <div class="author">{{articalDetail.user_name}}</div>
        <div class="time">{{articalDetail.create_time|changeNum|formatDate("yyyy-MM-dd hh:mm")}}</div>
      </div>
      <div class="pic">
        <img :src="articalDetail.img" alt />
      </div>
      <div class="text" v-html="articalDetail.content">
      </div>
      <div class="num">
        <div class="left">
          阅读
          <span>{{articalDetail.views}}</span>
        </div>
        <div class="right" @click="zan">
          <img src="../assets/images/praise.png" alt />
          <span>点赞{{articalDetail.like}}</span>
        </div>
      </div>
    </div>
    <div class="comment">
      <div class="commentTitle">评论{{commentList.length}}</div>
      <ul>
        <li v-for="(item,index) in commentList" :key="index">
          <div class="pic">
            <img :src="item.avatar" alt />
          </div>
          <div class="info">
            <div class="row1">
              <div class="left">{{item.username}}</div>
              <div class="right" @click="zan">
                <img src="../assets/images/praise2.png" alt />
                <span>{{item.like}}</span>
              </div>
            </div>
            <div class="row2">{{item.content}}</div>
          </div>
        </li>
      </ul>
    </div>
    <div class="footer" @click="zan">
      <input type="text" placeholder="评论" />
    </div>
    <div class="downloadApp">
      <van-dialog
        v-model="showDownload"
        :show-confirm-button="false"
        :close-on-click-overlay="true"
      >
        <div class="downloadDialog">
          <div class="text">请前往现信APP继续操作</div>
          <div class="btn" @click="downloadApp">马上下载现信APP</div>
        </div>
      </van-dialog>
    </div>
     <div v-if="showBind">
      <bindPhone :uid="false" :activity_id="false"></bindPhone>
    </div>
  </div>
</template>
<script>
import vuefilter from "../common/vuefilter.js";
export default {
  name: "artical",
  filters: {
    formatDate: vuefilter.formatDate,
    changeNum: vuefilter.changeNum
  },
  data() {
    return {
      //文章ids
      id:"",
      uid:"",
      articalDetail:{},
      commentList:{},
      showBind:false,
      showDownload:false,
    };
  },
  mounted() {
    this.id=this.$route.query.id;
    this.uid=this.$route.query.uid;
    this.getArticalDetail();
    this.getCommentList();
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },
    async getArticalDetail() {
      let params = {
        token: this.$cookies.get("token"),
        id: this.uid
      };
      const res = await this.$axios.post(this.$api.getArticle, params);
      if (res.code == 1) {
        this.articalDetail = res.data;
      } else {
        this.$message({
          message: "获取文章详情失败：" + res.msg,
          type: "error"
        });
      }
    },
    async getCommentList() {
      let params = {
        token: this.$cookies.get("token"),
        article_id: this.uid
      };
      const res = await this.$axios.post(this.$api.getComments, params);
      if (res.code == 1) {
        this.commentList = res.data;
      } else {
        this.$message({
          message: "获取评论列表失败：" + res.msg,
          type: "error"
        });
      }
    },
    zan(){
      if (this.$cookies.get("first_login")!=0) {
        this.showBind = true;
        return;
      };
      this.showDownload=true;
    },
     //下载APP
    downloadApp() {
        window.location.href = this.$api.downloadUrl;
    }
  }
};
</script>
<style scoped>
.artical {
  min-height: 100vh;
  padding-top: 0.46rem;
  padding-bottom: 0.5rem;
}
.detail {
  margin-top: 0.08rem;
  background: #fff;
  padding: 0.14rem 0.15rem 0.13rem;
}
.detail .title {
  font-size: 0.15rem;
  font-family: PingFangSC-Medium;
  font-weight: 500;
  color: rgba(0, 0, 0, 1);
}
.detail .subtitle {
  margin-top: 0.1rem;
  display: flex;
}
.detail .subtitle .author {
  font-size: 0.12rem;
  font-family: PingFangSC-Medium;
  font-weight: 500;
  color: rgba(0, 0, 0, 1);
  margin-right: 0.1rem;
}
.detail .subtitle .time {
  font-size: 0.12rem;
  font-family: PingFangSC-Regular;
  font-weight: 400;
  color: rgba(94, 94, 94, 1);
}
.detail .pic {
  margin-top: 0.1rem;
}
.detail .pic img {
  width: 100%;
}
.detail .text {
  margin-top: 0.18rem;
}
.detail .num {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.18rem;
}
.detail .num .left {
  font-size: 0.14rem;
  font-family: PingFangSC;
  font-weight: 400;
  color: rgba(107, 107, 107, 1);
}
.detail .num .left span {
  padding-left: 0.1rem;
}
.detail .num .right {
  display: flex;
  align-items: center;
}
.detail .num .right img {
  width: 0.14rem;
  height: 0.14rem;
}
.detail .num .right {
  font-size: 0.14rem;
  font-family: PingFangSC;
  font-weight: 400;
  color: rgba(83, 116, 170, 1);
}
.detail .num .right span {
  padding-left: 0.08rem;
}
.comment {
  margin-top: 0.13rem;
  background: #f3f3f3;
  padding: 0.14rem 0.15rem;
}
.comment .commentTitle {
  font-size: 0.12rem;
  font-family: PingFangSC;
  font-weight: 400;
  color: rgba(107, 107, 107, 1);
  margin-bottom: 0.26rem;
}
.comment li {
  display: flex;
  margin-bottom: 0.25rem;
}
.comment li .pic {
  display: flex;
  align-items: center;
}
.comment li .pic img {
  width: 0.4rem;
  height: 0.4rem;
}
.comment li .info {
  padding-left: 0.1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.comment li .info .row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.comment li .info .row1 .left {
  font-size: 0.12rem;
  font-family: PingFangSC;
  font-weight: 400;
  color: rgba(107, 107, 107, 1);
}
.comment li .info .row1 .right {
  display: flex;
  align-items: center;
  font-size: 0.12rem;
  font-family: PingFangSC;
  font-weight: 400;
  color: rgba(107, 107, 107, 1);
}
.comment li .info .row1 .right span {
  padding-left: 0.06rem;
}
.comment li .info .row1 .right img {
  width: 0.12rem;
  height: 0.12rem;
}
.comment li .info .row2 {
  font-size: 0.12rem;
  font-family: PingFangSC;
  font-weight: 400;
  color: rgba(32, 32, 32, 1);
}
.footer {
  width: 100%;
  height: 0.5rem;
  background: #fff;
  padding: 0 0.15rem;
  display: flex;
  align-items: center;
  position: fixed;
  left: 0;
  bottom: 0;
}
.footer input {
  width: 100%;
  height: 0.34rem;
  background: #f3f3f3;
  border-radius: 5px;
  border: none;
  padding-left: 0.12rem;
}
.downloadDialog {
  padding: 0.3rem;
}
.downloadDialog .text {
  text-align: center;
  margin-bottom: 0.2rem;
}
.downloadDialog .btn {
  width: 100%;
  height: 0.4rem;
  background: #00c6d8;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}
</style>


